package com.ssi.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.ssi.domain.user.User;

public class EncodingFilter implements Filter {
	String encoding="UTF-8";
	public void destroy() {
		// TODO Auto-generated method stub

	}

	public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
			FilterChain filterChain) throws IOException, ServletException {
		HttpServletRequest request = (HttpServletRequest) servletRequest;
		HttpServletResponse response = (HttpServletResponse) servletResponse;
		String path=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()
		+request.getContextPath()+"/";
		request.getSession().setAttribute("path", path);
		filterChain.doFilter(servletRequest, servletResponse);	
		if(encoding!=null)
		{
		request.setCharacterEncoding(encoding);
		response.setContentType("text/html;charset="+encoding);
		}
	}

	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub

	}

}
